﻿package mortal.game.view.guildWar
{
    import Message.Public.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.*;
    import mortal.game.view.mainUI.smallMap.view.*;
    import mortal.mvc.core.*;

    public class GuildWarMiniView extends CopyInfoPanelBase
    {
        private var _smallMap:SmallMapEmbedView;
        private var _linkButtonBang:GButton;
        private var _leftTime:GuildWarSecTimeView;
        private var _exploit:GTextFiled;
        private var _contribute:GTextFiled;
        private var _kill:GTextFiled;
        private var _myFieldScore:GuildWarFiledCell;
        private var _enemyFieldScore:GuildWarFiledCell;
        private var _vipImg:GImageBitmap;
        private var _getExtraBtn:GButton;
        private var _btnExit:GLoadingButton;
        private static var _instance:GuildWarMiniView;

        public function GuildWarMiniView()
        {
            super(ImagesConst.copyInfoPanelTitleGuildWar, 262, 569);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            setSize(262, 569);
            _moveBtn.x = 8;
            _moveBtn.y = 13;
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.GuildWarMiniViewBg, 0, 0, _bodySprite));
            this._smallMap = UIFactory.smallMapEmbedView(ImagesConst.GuildWarMiniMap, 16, 43, _bodySprite, true);
            this._smallMap.run();
            var _loc_1:int = 287;
            this._leftTime = UIFactory.getUICompoment(GuildWarSecTimeView);
            this._leftTime.defaultTextFormat = GlobalStyle.textFormatLv.setSize(13).setBold(true);
            this._leftTime.filters = [FilterConst.glowFilter];
            this._leftTime.setParse(Language.getString(11416));
            UIFactory.setObjAttri(this._leftTime, 30, _loc_1, 150, 20, _bodySprite);
            this._linkButtonBang = UIFactory.gButton(Language.getString(11417), 18, _loc_1 - 39, 78, 22, _bodySprite, "BlueLinkButton");
            this._linkButtonBang.configEventListener(MouseEvent.CLICK, this.onClickBang);
            this._exploit = UIFactory.gTextField(Language.getStringByParam(11418, "0"), 25, 30 + _loc_1, 70, 20, _bodySprite);
            this._contribute = UIFactory.gTextField(Language.getStringByParam(11419, "0"), 100, 30 + _loc_1, 70, 20, _bodySprite);
            this._kill = UIFactory.gTextField(Language.getStringByParam(11420, "0"), 175, 30 + _loc_1, 70, 20, _bodySprite);
            this._myFieldScore = UIFactory.getUICompoment(GuildWarFiledCell, 10, 59 + _loc_1, _bodySprite);
            this._enemyFieldScore = UIFactory.getUICompoment(GuildWarFiledCell, 10, 131 + _loc_1, _bodySprite);
            this._vipImg = UIFactory.gImageBitmap("", 30, 181 + _loc_1, _bodySprite);
            this._getExtraBtn = UIFactory.gButton(Language.getString(11421), 194, 181 + _loc_1, 49, 22, _bodySprite);
            this._btnExit = UIFactory.gLoadingButton(ResFileConst.ExitCopyBtn, 72, 220 + _loc_1, 103, 38, _bodySprite);
            this._getExtraBtn.configEventListener(MouseEvent.CLICK, this.onClickGetExtra);
            this._btnExit.configEventListener(MouseEvent.CLICK, this.onClickExit);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            EffectManager.glowFilterUnReg(this._getExtraBtn);
            this._smallMap.dispose(param1);
            this._smallMap = null;
            this._leftTime.dispose(param1);
            this._leftTime = null;
            this._exploit.dispose(param1);
            this._exploit = null;
            this._contribute.dispose(param1);
            this._contribute = null;
            this._kill.dispose(param1);
            this._kill = null;
            this._myFieldScore.dispose(param1);
            this._myFieldScore = null;
            this._enemyFieldScore.dispose(param1);
            this._enemyFieldScore = null;
            this._linkButtonBang.dispose(param1);
            this._linkButtonBang = null;
            this._vipImg.dispose(param1);
            this._vipImg = null;
            this._getExtraBtn.dispose(param1);
            this._getExtraBtn = null;
            this._btnExit.dispose(param1);
            this._btnExit = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function onClickGetExtra(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildWarGetVIPExploit));
            return;
        }// end function

        private function onClickExit(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CopyClickQuickBtn));
            return;
        }// end function

        public function updateAll() : void
        {
            this.updateLeftTime();
            this.updateGuildScore();
            this.updatePlayerScore(Cache.instance.guildWar.myScore);
            return;
        }// end function

        public function updateLeftTime() : void
        {
            if (Cache.instance.guildWar.guildWarSingleTimeInt)
            {
                this._leftTime.setLeftTime(Cache.instance.guildWar.guildWarSingleTimeInt.publicInt, true);
            }
            return;
        }// end function

        public function updatePlayerScore(param1:SMyGuildWarScore) : void
        {
            if (param1)
            {
                ObjTeamCreate.setTextFieldKeyValue(this._exploit, Language.getString(11422), param1.exploit.toString(), GlobalStyle.colorPutong, GlobalStyle.colorHuang);
                ObjTeamCreate.setTextFieldKeyValue(this._contribute, Language.getString(11423), param1.contribute.toString(), GlobalStyle.colorPutong, GlobalStyle.colorHuang);
                ObjTeamCreate.setTextFieldKeyValue(this._kill, Language.getString(11424), param1.kill.toString(), GlobalStyle.colorPutong, GlobalStyle.colorHuang);
                if (Cache.instance.vip.level < 3)
                {
                    this._vipImg.imgUrl = ImagesConst.GuildWarExtraNo;
                    this._getExtraBtn.visible = false;
                }
                else if (Cache.instance.vip.level < 6)
                {
                    this._vipImg.imgUrl = ImagesConst.GuildWarExtra1;
                    if (param1.hasVipExploit)
                    {
                        EffectManager.glowFilterReg(this._getExtraBtn);
                        this._getExtraBtn.visible = true;
                    }
                    else
                    {
                        EffectManager.glowFilterUnReg(this._getExtraBtn);
                        this._getExtraBtn.visible = false;
                    }
                }
                else if (Cache.instance.vip.level < 9)
                {
                    this._vipImg.imgUrl = ImagesConst.GuildWarExtra2;
                    if (param1.hasVipExploit)
                    {
                        EffectManager.glowFilterReg(this._getExtraBtn);
                        this._getExtraBtn.visible = true;
                    }
                    else
                    {
                        EffectManager.glowFilterUnReg(this._getExtraBtn);
                        this._getExtraBtn.visible = false;
                    }
                }
                else
                {
                    this._vipImg.imgUrl = ImagesConst.GuildWarExtra3;
                    if (param1.hasVipExploit)
                    {
                        EffectManager.glowFilterReg(this._getExtraBtn);
                        this._getExtraBtn.visible = true;
                    }
                    else
                    {
                        EffectManager.glowFilterUnReg(this._getExtraBtn);
                        this._getExtraBtn.visible = false;
                    }
                }
                if (!this._getExtraBtn.visible)
                {
                    this._vipImg.x = 30;
                }
                else
                {
                    this._vipImg.x = 10;
                }
            }
            return;
        }// end function

        public function updateGuildScore() : void
        {
            if (Cache.instance.guildWar.myGuildWarScore)
            {
                this._myFieldScore.updateFieldScore(Cache.instance.guildWar.myGuildWarScore, true);
                if (Cache.instance.guildWar.enemyGuildWarScore)
                {
                    this._enemyFieldScore.updateFieldScore(Cache.instance.guildWar.enemyGuildWarScore, false);
                    this._enemyFieldScore.visible = true;
                }
                else
                {
                    this._enemyFieldScore.visible = false;
                }
            }
            return;
        }// end function

        private function onClickBang(event:MouseEvent) : void
        {
            GuildWarRankWindow.instance.show();
            return;
        }// end function

        public static function get instance() : GuildWarMiniView
        {
            if (!_instance)
            {
                _instance = new GuildWarMiniView;
            }
            return _instance;
        }// end function

        public static function hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

    }
}
